package com.wanmait.wanmarecruit.manageControllerAdvice;

import com.auth0.jwt.exceptions.JWTVerificationException;
import com.wanmait.wanmarecruit.enumeration.ErrorEnum;
import com.wanmait.wanmarecruit.util.AjaxResult;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authz.UnauthorizedException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class ManageControllerAdvice {
    @ExceptionHandler(JWTVerificationException.class)
    public AjaxResult processJWTVerificationException(JWTVerificationException e)
    {
        return AjaxResult.error(ErrorEnum.TOKEN_FAILED.getCode(),e.getMessage());
    }

    @ExceptionHandler(AuthenticationException.class)
    public AjaxResult processAuthenticationException(AuthenticationException e){
        return AjaxResult.error(ErrorEnum.TOKEN_FAILED.getCode(),e.getMessage());
    }
    @ExceptionHandler(UnauthorizedException.class)
    public AjaxResult processUnauthorizedException(UnauthorizedException e){
        return AjaxResult.error(ErrorEnum.UNAUTHORIZED.getCode(), e.getMessage());
    }

}
